﻿#ifndef COMMONTYPE_H
#define COMMONTYPE_H
#include <QtGui>
#include <QTextStream>
#include <QTableWidget>
#include <QTextEdit>
#include <QApplication>
#include <QDesktopWidget>
#include <QtMessageHandler>
#include <QMessageBox>

#define APPDIR QApplication::applicationDirPath()
#define myDebug      qDebug()<< __FILE__ << __LINE__ << ":"

typedef struct
{
    char head[4];
    uint cmd;
    uint len;
}PackHead;

double s2d(QString s,bool *ok=0);
double s2i(QString s,bool *ok=0);
float s2f(QString s);
QString i2s(int i);
QString i3s(int i);
QString d2s(double d, int fraction=4);
QString u2s(unsigned int u);
QString f2s(float f, int fraction=4);

QString splitNum_Unit(QString inStr, QString &strUnit);
void MySleep(int msec);
QString ByteArray2HexString(QByteArray &ba);
bool writeInit(QString group, QString user_key, QString user_value);
bool readInit(QString group, QString user_key, QString &user_value);
QString getCompileDate();
double glys2xj(QString glys);
double wchz(double yz, double jd);
QString getSubStr(QString strFrom,QString strBegin,QString strEnd);
QString getSubStr(QString strFrom,QString strBegin);
int bytesToInt(QByteArray bytes);
QByteArray  intToByte(int number);
float bytesToFloat(QByteArray bytes);
QByteArray  floatToByte(float number);
bool copyFileToPath(QString fromFile , QString toFile, bool coverFileIfExist);
bool copyDirectoryFiles(const QString &fromDir, const QString &toDir, bool coverFileIfExist);
int DeleteFileInDir(const QString dirPath,QString strBegin);
int GetSelectedRow(QTableWidget *table);
QString getCellValue(QTableWidget *table,int r, int c);
void setCellValue(QTableWidget *table, int r, int c, QString v, bool bOk=true);
void centerWin(QWidget *w);
//float geScaleFactor();

void getLangFromXml();
void setLangToXml();

//日志系统
void openLog(QTextEdit *txtLog=NULL);
void closeLog();
void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);

void RunExe(QString strFullPath);
QString GetDocumentPath(); //得到 我的文档 的全路径
QString GetAppDataPath();
QString GetTempPath();
QString GetLocalDataPath();
bool MsgBox(QWidget *parent,QString msg,int dlgType);

QString gbk2utf8(QString strIn);
#endif // COMMONTYPE_H
